<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class like extends ActiveRecord{
       public static function tableName(){
             return "{{%like}}";
     }
       
       public function rules(){
          return[
             [['content_id','openid'],'required','message' => 'fail'],
            ];
       }
 
       public function add($data){
            if($data){
                //处理数据
              $content_id = $data['formid'];
              $openid = $data['username'];
                //创建时间
              date_default_timezone_set('PRC');
              $createtime = date('Y-m-d H:i:s');
                //输入数据库
              $this->content_id = $content_id;
              $this->openid = $openid;
              $this->createtime = $createtime;
              $result = $this->save();
              if($result){
                   $error = 0;
                   return $error;
             }else{
                 $error = $this->getErrors();
                 return $error;
              }
           }else{
                 $error = 2;
                 return $error;
        }
   }
               


}
